var app = getApp()
var CommonUtils = app.CommonUtils
var keys = require("../../assets/data/keys.js")

Page({
  data: {
    navLeftItems: [],
    navRightItems: [],
    curNav: 0,
    curIndex: 0
  },
  onLoad: function () {
    wx.showLoading({
      title: '数据加载中',
    })
    var that = this
    wx.request({
      url: keys.data.url_Product_Type,
      success: function (res) {
        var tempDatas = res.data.datas;
        for (var i = 0; i < tempDatas.length; i++) {
          var tempErji = tempDatas[i].erji;
          for (var j = 0; j < tempErji.length; j++) {
            tempErji[j].id = i;
          }
        }
        that.navLeftItems = tempDatas;
        that.navRightItems = tempDatas[0].erji[0].sanji;
        that.setData({
          navLeftItems: that.navLeftItems,
          navRightItems: that.navRightItems
        })
      },
      complete: function (res) {
        wx.hideLoading()
      }
    })
  },

  //事件处理函数
  switchRightTab: function (e) {
    let id = parseInt(e.target.dataset.id), index = parseInt(e.target.dataset.index);
    console.log(id)
    console.log(index)
    this.setData({
      curNav: id,
      curIndex: index,
      navRightItems: this.navLeftItems[id].erji[index].sanji,
    })

  },

  //跳转到商品详情页
  jumpGoodsInfo: function (e) {
    var _this = this;
    if (app.login_id.length > 0) {
      wx.navigateTo({
        url: "/pages/goods-details/index?id=" + _this.data.navRightItems[e.currentTarget.dataset.index].HJP_ID
      })
    } else {
      wx.showModal({
        title: '请登陆',
        success: function (res) {
          if (res.confirm) {
            wx.navigateTo({
              url: '../login/index',
            })
          }
        }
      })
    }
  }
})